﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace store.cyt369.com.dal.DbContexts
{
    //public partial class CYT369BrandContext : Microsoft.EntityFrameworkCore.DbContext
    public partial class CYT369StoreContext : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityDbContext<store.cyt369.com.models.Identity.SysUser,
                                                                                                        store.cyt369.com.models.Identity.UserType,
                                                                                                        int,
                                                                                                        store.cyt369.com.models.Identity.UserClaim,
                                                                                                        store.cyt369.com.models.Identity.UserRole,
                                                                                                        store.cyt369.com.models.Identity.UserLogin,
                                                                                                        store.cyt369.com.models.Identity.RoleClaim,
                                                                                                        store.cyt369.com.models.Identity.UserToken>
    {
        private store.cyt369.com.utility.Connection m_Connection;
        public CYT369StoreContext()
        {
            m_Connection = store.cyt369.com.utility.SystemSettingService.Instance.StoreDB;
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (m_Connection != null)
            {
                //if (m_Connection.DBType == store.cyt369.com.utility.ConstStringClass.SQLSERVER2008 ||
                //    m_Connection.DBType == store.cyt369.com.utility.ConstStringClass.SQLSERVER2005)
                //{
                //    optionsBuilder.UseSqlServer(m_Connection.ConnectionString).ReplaceService<Microsoft.EntityFrameworkCore.Query.IQueryTranslationPostprocessorFactory, Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServer2008QueryTranslationPostprocessorFactory>();
                //}
                //else
                //{
                //    optionsBuilder.UseSqlServer(m_Connection.ConnectionString);
                //}

                optionsBuilder.UseSqlServer("Data Source=47.109.25.242;Initial Catalog=store.cyt369.com;user id=sa;pwd=Zgy20020627;encrypt=false;TrustServerCertificate=True;");
            }
            base.OnConfiguring(optionsBuilder);
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            string schema = null;
            if (m_Connection != null)
            {
                schema = m_Connection.DBSchema;
            }

            DocModelCreating(builder, schema);
        }

        private void DocModelCreating(ModelBuilder modelBuilder, string schema)
        {

        }


    }
}
